﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using PowerCreator.LMS.BBS.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common;
using Telerik.WebControls;

public partial class Theme_3_OpenVideo : PowerCreator.LMS.Web.Base.BasePage
{
    //const string AccessoryVedio = "<object align=\"right\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" id=\"MediaPlayer\"" +
    //          " width=\"100%\" height=\"100%\" type=\"application/x-oleobject\" standby=\"Loading Microsoft? Windows? Media Player components...\">" +
    //          "<param name=\"URL\" value=\"{0}\">" +
    //           "<param name=\"rate\" value=\"1\">" +
    //           "<param name=\"balance\" value=\"0\">" +
    //          " <param name=\"currentPosition\" value=\"0\">" +
    //           "<param name=\"defaultFrame\">" +
    //           "<param name=\"playCount\" value=\"1\">" +
    //           "<param name=\"autoStart\" value=\"-1\">" +
    //           "<param name=\"currentMarker\" value=\"0\">" +
    //           "<param name=\"invokeURLs\" value=\"-1\">" +
    //           "<param name=\"baseURL\">" +
    //          " <param name=\"volume\" value=\"100\">" +
    //           "<param name=\"mute\" value=\"0\">" +
    //           "<param name=\"uiMode\" value=\"full\">" +
    //           "<param name=\"stretchToFit\" value=\"-1\">" +
    //           "<param name=\"windowlessVideo\" value=\"0\">" +
    //           "<param name=\"enabled\" value=\"-1\">" +
    //           "<param name=\"enableContextMenu\" value=\"-1\">" +
    //           "<param name=\"fullScreen\" value=\"0\">" +
    //           "<param name=\"SAMIStyle\">" +
    //           "<param name=\"SAMILang\">" +
    //           "<param name=\"SAMIFilename\">" +
    //           "<param name=\"captioningID\">" +
    //       "</object>";
    //protected string url = string.Empty;
    //PowerCreator.LMS.Web.BBS.ManagerBBS opBBS = new PowerCreator.LMS.Web.BBS.ManagerBBS();
    //protected void Page_Load(object sender, EventArgs e)
    //{
    //    //url = Request.QueryString["ID"].ToString();
    //    //PowerCreator.LMS.BBS.Entity.VOTheme voTheme = new VOTheme();
    //    //voTheme = opBBS.LoadTheme(int.Parse(ViewState["ThemeID"].ToString()));
    //    //url = string.Format(AccessoryVedio, "/fileManager/UploadFile/BBS/" + url);
    //}
    PowerCreator.LMS.Web.Course.Course opCourse = new PowerCreator.LMS.Web.Course.Course();
    private PowerCreator.LMS.Web.DL.User.LoginEntity login = new PowerCreator.LMS.Web.DL.User.LoginEntity();
    PowerCreator.LMS.Web.Course.Resource opResource = new PowerCreator.LMS.Web.Course.Resource();
    protected string fileUrl = string.Empty;
    private string Loginurl = "../../Default.aspx";
    protected void Page_Load(object sender, EventArgs e)
    {
        Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        CheckPage();
        CheckUser();
        if (Request.QueryString["rsd"] != null)
        {
            ViewState["ResourceID"] = Request.QueryString["rsd"].ToString();

            BinderPG();

            
        }
    }


    private void CheckPage()
    {
        if (Request.UrlReferrer == null)
        {
            Script.RedirectURL(Loginurl);
        }
        if (Request.Url.Host != Request.UrlReferrer.Host)
        {
            Script.RedirectURL(Loginurl);
        }
    }

    private void CheckUser()
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            Script.RedirectURL(Loginurl);
        }

        login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
        if (login == null)
        {
            Script.RedirectURL(Loginurl);
        }

    }


    private void BinderPG()
    {
        //初始化界面的播放地址
        PowerCreator.LMS.Course.Entity.VOTResource voResource = opCourse.LoadResource(int.Parse(ViewState["ResourceID"].ToString()));

        if (voResource.ResourceID < 0)
        {
            Script.ShowAndCloseMe(Page, config.GetLanagerValueByKey("theme_Comment_OpenCourseware_Msg1", PowerCreator.LMS.Language.LanagetItemType.Page));
            return;
        }


        string ServerIP;
        int index = Request.Url.Authority.IndexOf(":", 0);
        if (index != -1)
        {
            ServerIP = Request.Url.Authority.Remove(index);
        }
        else
        {
            ServerIP = Request.Url.Authority;
        }


        PowerCreator.LMS.ViewQuery.ViewQuery opView = new PowerCreator.LMS.ViewQuery.ViewQuery();
        string sDirName = opResource.GetDirctoryName(voResource.ResourceUrl);
        string search = "select VirId,VirIisName,VirMmsName,VirIp from TVirtualDirectory where VirIisName='" + sDirName + " '";
        DataTable dtDir = opView.Query(search);
        if (dtDir.Rows.Count == 1)
        {
            if (PowerCreator.LMS.Web.Config.WebConfig.IsUseURLIP)
            {

                string sResourceMMSUrl = voResource.ResourceUrl.Replace(sDirName, dtDir.Rows[0]["VirMmsName"].ToString());
                fileUrl = "mms://" + ServerIP + sResourceMMSUrl + voResource.ResourceEntry;
            }
            else
            {
                ServerIP = dtDir.Rows[0]["VirIp"].ToString();
                string sResourceMMSUrl = voResource.ResourceUrl.Replace(sDirName, dtDir.Rows[0]["VirMmsName"].ToString());
                fileUrl = "mms://" + ServerIP + sResourceMMSUrl + voResource.ResourceEntry;

            }
        }
        else
        {
            fileUrl = "mms://" + ServerIP + voResource.ResourceUrl + voResource.ResourceEntry;
        }


    }

}
